﻿using System;
using System.IO;
using System.Reflection;
using System.Web.Http;
using AutoFacWrapper;
using ZLWeb.WebApiConfigration;
using ZLWeb.WebApiConfigration.WebapiAppsetting;

namespace ZLWeb.WebApiApplication
{
    /// <summary>
    ///     启动类
    /// </summary>
    public class Bootstrapper
    {
        public static void Run()
        {
            SetAutofacWebAPIServices();
            var configpath = AppDomain.CurrentDomain.BaseDirectory;
#if DEBUG
            if (configpath.LastIndexOf(@"bin", StringComparison.Ordinal) == -1)
            {
                configpath = configpath + @"bin";
            }
#endif

           // ZLLogger.SetConfig(new FileInfo(configpath + "\\Log4Config.xml"));

           // PipeWebServiceConfig.SetConfig(new FileInfo(configpath + "\\ZLWebPipeConfig.xml"));

            ZLWebApiAppSetting.GetAppSetting().LoadData(configpath + "\\ZLWebApiAppSetting.xml");
        }

        /// <summary>
        ///     注册并关联到系统DependencyResolver
        /// </summary>
        private static void SetAutofacWebAPIServices()
        {
            ClassFactory.RegisterApiControllers(Assembly.Load("ZLWeb.WebApiControllers"));
            ClassFactory.RegisterAssemblis(Assembly.Load("ZLWeb.WebApiRepository"));
            ClassFactory.RegisterDependencyResolver(GlobalConfiguration.Configuration.DependencyResolver);
        }
    }
}